<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>欢迎回来</h1>
    <ul class="infoList"></ul>

    <script>
      fetch("http://localhost:3000/home/list")
        .then((res) => {
          return res.json();
        })
        .then((res) => {
          render(res);
        })
        .catch((err) => {
          console.log(err);
        });

      function render(data) {
        // 获取标题
        let headBox = document.querySelector("h1");
        headBox.innerHTML = `欢迎回来，${data.name}`;
        // 获取列表
        let listBox = document.querySelector(".infoList");
       
        let list = data.info.map((item) => {
          return `<li>${item}</li>`;
        });
        listBox.innerHTML = list.join("");
      }
    </script>
  </body>
</html>
